
import 'dart:convert';

import '../../../data/models/auth/user.dart';
import '../../exercises/exercises_page/models/exercise.dart';
import '../../gyms/gyms_page/models/gym.dart';

NoteModel noteModelFromJson(String str) => NoteModel.fromJson(json.decode(str));

String noteModelToJson(NoteModel data) => json.encode(data.toJson());

class NoteModel {
  final String? noteId;
  final String text;
  final String exerciseId;
  final DateTime? createAt;
  final String? createdBy;
  final User? user;
  final Exercise? exercise;
  final Gym? gym;

  NoteModel({
    this.noteId,
    required this.text,
    required this.exerciseId,
    this.createAt,
    this.createdBy,
    this.user,
    this.exercise,
    this.gym,
  });

  NoteModel copyWith({
    String? noteId,
    String? text,
    String? exerciseId,
    DateTime? createAt,
    String? createdBy,
    User? user,
    Exercise? exercise,
    Gym? gym,
  }) =>
      NoteModel(
        noteId: noteId ?? this.noteId,
        text: text ?? this.text,
        exerciseId: exerciseId ?? this.exerciseId,
        createAt: createAt ?? this.createAt,
        createdBy: createdBy ?? this.createdBy,
        user: user ?? this.user,
        exercise: exercise ?? this.exercise,
        gym: gym ?? this.gym,
      );

  factory NoteModel.fromJson(Map<String, dynamic> json) => NoteModel(
    noteId: json["note_id"]?.toString(),
    text: json["text"],
    exerciseId: json["exercise_id"].toString(),
    createAt: DateTime.parse(json["create_at"]),
    createdBy: json["created_by"]?.toString(),
    user: User.fromJson(json["user"]),
    exercise: Exercise.fromJson(json["exercise"]),
    gym: Gym.fromJson(json["gym"]),
  );

  Map<String, dynamic> toJson() => {
    "note_id": noteId,
    "text": text,
    "exercise_id": exerciseId,
    "create_at": createAt?.toIso8601String(),
    "created_by": createdBy,
    "user": user?.toJson(),
    "exercise": exercise?.toJson(),
    "gym": gym?.toJson(),
  };
}

